<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/alllayui/layui/css/layui.css}"  media="all">
    <script th:src="@{/alllayui/layui/layui.js}" charset="utf-8"></script>
    <script th:src="@{/system/js/jquery.min.js}" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改角色</legend>
</fieldset>

<form class="layui-form" action="">
                <input type="hidden" name="id" th:value='${role.id}'  >
                <div class="layui-form-item">
                    <label class="layui-form-label">角色id</label>
                    <div class="layui-input-block">
                                <input type="text" name='roleKey'  th:value='${role.roleKey}' lay-verify="required" lay-reqtext="角色id为必填项" placeholder="请输入角色id" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色描述</label>
                    <div class="layui-input-block">
                                <input type="text" name='roleDesc'  th:value='${role.roleDesc}' lay-verify="required" lay-reqtext="角色描述为必填项" placeholder="请输入角色描述" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">父角色id</label>
                    <div class="layui-input-block">
                                <input type="text" name='pRoleKey' fkAttr='role_role_fk'  th:value='${role.pRoleKey}' lay-verify="required" lay-reqtext="父角色id为必填项" placeholder="请输入父角色id" autocomplete="off" class="layui-input foreignKey">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">父角色描述</label>
                    <div class="layui-input-block">
                                <input type="text" name='pRoleDesc'  th:value='${role.pRoleDesc}' lay-verify="required" lay-reqtext="父角色描述为必填项" placeholder="请输入父角色描述" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                             <select name='enable'  lay-verify="required">
                                 <option value="">请选择</option>
                                     <option value="0"  th:selected='${ role.enable == 0 }'   >启用</option>
                                     <option value="1"  th:selected='${ role.enable == 1 }'   >禁用</option>
                             </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                                <input type="text" name='sort'  th:value='${role.sort}' lay-verify="required" lay-reqtext="排序为必填项" placeholder="请输入排序" autocomplete="off" class="layui-input">
                    </div>
                </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="subBtn">提交</button>
        </div>
    </div>
</form>
<script>
    layui.use(['jquery','form','laydate'], function(){
        var thisIndex = parent.layer.getFrameIndex(window.name);
        var form = layui.form
            ,layer = layui.layer
            ,$ = layui.$ ;

        var laydate = layui.laydate;

        //同时绑定多个
        lay('.datePicker').each(function(){
            laydate.render({
                elem: this
                ,trigger: 'click'
            });
        });

        //同时绑定多个
        $(document).on('click','.foreignKey',function(){
            let fkAttr = $(this).attr("fkAttr");
            //iframe层-父子操作
            if(fkAttr!=""){
                layer.open({
                    type: 2,
                    area: ['700px', '450px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: '/role/choosePage?fkName=' +  fkAttr
                });
            }
        });

        var parentLayer = parent.layer;
        var pWindow = parent ;
        form.on('submit(subBtn)', function(data){
            let data2Send = data.field;
            $.post("/role/update",data2Send,function (res) {
                var msg = "";
                if(res.message == 'SUCCESS'){
                    msg = '修改成功!窗口关闭';
                } else {
                    msg = '修改失败!窗口关闭'
                }
                parentLayer.msg(msg, {
                    icon: 1,
                    time: 2000
                }, function(){
                    parentLayer.close(thisIndex);
                    pWindow.document.getElementById('searchBtn').click();
                });
            },"json");
        });
    });

    function coverValue(coverValueColumn,chooseInfo) {
        //console.log("父页面");
        //console.log(coverValueColumn);
        //console.log(chooseInfo);
        let parse = JSON.parse(coverValueColumn);
        var valObj  ;
        if(chooseInfo){
            valObj = chooseInfo[0];
        }
        //console.log(valObj);
        for(let i=0;i<parse.length;i++){
            var coverObj = parse[i];
            setFormValue(coverObj.mTable,valObj[coverObj.rSql]);
        }
    }

    function setFormValue(componentId,val) {
        document.getElementsByName(componentId)[0].value = val;
    }

</script>

</body>